<?php

Yii::import('zii.widgets.CMenu');

class MyMenu extends CMenu
{
	public $operations;
	
	public function init()
	{
		$this->htmlOptions['id']=$this->getId();
		$route=$this->getController()->getRoute();
		$route=substr($route,0,-strlen(strrchr($route,'/')));
		$this->items=$this->normalizeItems($this->items,$route,$hasActiveChild);
	}

	protected function normalizeItems($items,$route,&$active)
	{
		foreach($items as $i=>$item)
		{
			if(isset($item['visible']) && !$item['visible'])
			{
				unset($items[$i]);
				continue;
			}
			if($this->encodeLabel)
				$items[$i]['label']=CHtml::encode($item['label']);
			$hasActiveChild=false;
			if(isset($item['items']))
			{
				$items[$i]['items']=$this->normalizeItems($item['items'],$route,$hasActiveChild);
				if(empty($items[$i]['items']) && $this->hideEmptyItems)
					unset($items[$i]['items']);
			}
			if(!isset($item['active']))
			{
				if($this->activateParents && $hasActiveChild || $this->activateItems && $this->isItemActive($item,$route))
				{
					$active=$items[$i]['active']=true;
					if (isset($this->operations)) {
						$items[$i]['items']=$this->normalizeItems($this->operations,'false',$hasActiveChild123);	// добавление операций в подменю
						if(empty($items[$i]['items']) && $this->hideEmptyItems)
							unset($items[$i]['items']);
					}
				}
				else
					$items[$i]['active']=false;
			}
			else if($item['active'])
				$active=true;
		}
		return array_values($items);
	}
}